package com.sxkj.web.controller.version;

import com.sxkj.common.response.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import com.github.pagehelper.PageInfo;
import com.sxkj.entity.entity.version.VersionScaleRecord;
import com.sxkj.service.version.VersionScaleRecordService;

/**
 * @author Zhang Xingliang
 *
 * @description: 秤更新状态记录
 * @date 2019-12-31 13:25:41
 */
@RestController
@RequestMapping("/version/versionScaleRecord")
public class VersionScaleRecordController {

	@Autowired
	private VersionScaleRecordService versionScaleRecordService;

	@ApiOperation(value = "根据主键查秤更新状态记录信息")
	@GetMapping(value = "/get/{id}")
	public ResponseResult get(@PathVariable String id) {
		try {
			VersionScaleRecord versionScaleRecord = versionScaleRecordService.get(id);
			return ResponseResult.success(versionScaleRecord);
		} catch (Exception e) {
			return ResponseResult.failure(e.toString());
		}
	}

	/**
	 * @author Zhang Xingliang
	 * @description 更新版本信息记录状态
	 * @date 10:22 2019/11/19
	 * @param versionScaleRecord
	 * 			InstallFlag 0未安装 1已安装
	 * 			DownloadFlag 0未下载 1已下载
	 * 			Status 0未安装 1已安装
	 * @return ResponseResult
	 **/
	@ApiOperation(value = "新增秤更新状态记录信息")
	@RequestMapping(value = "/save", method = RequestMethod.POST)
	public ResponseResult save(@RequestBody VersionScaleRecord versionScaleRecord) {
		try {
			versionScaleRecordService.save(versionScaleRecord);
			return ResponseResult.success();
		} catch (Exception e) {
			return ResponseResult.failure(e.toString());
		}
	}

	@ApiOperation(value = "删除秤更新状态记录信息")
	@RequestMapping(value = "/delete", method = RequestMethod.POST)
	public ResponseResult delete(@RequestBody VersionScaleRecord versionScaleRecord) {
		try {
			versionScaleRecordService.delete(versionScaleRecord);
			return ResponseResult.success();
		} catch (Exception e) {
			return ResponseResult.failure(e.toString());
		}
	}

	@ApiOperation(value = "查询秤更新状态记录列表")
	@RequestMapping(value = "/findList", method = RequestMethod.POST)
	public ResponseResult findList(@RequestBody VersionScaleRecord versionScaleRecord) {
		try {
			return ResponseResult.success(versionScaleRecordService.findList(versionScaleRecord));
		} catch (Exception e) {
			return ResponseResult.failure(e.toString());
		}
	}

	@ApiOperation(value = "查询秤更新状态记录列表")
	@RequestMapping(value = "/findPage", method = RequestMethod.POST)
	public ResponseResult findPage(@RequestBody VersionScaleRecord versionScaleRecord,
			@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
			@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
		try {
			PageInfo pageInfo = versionScaleRecordService.findPage(versionScaleRecord, pageSize, pageNum);
			return ResponseResult.success(pageInfo);
		} catch (Exception e) {
			return ResponseResult.failure(e.toString());
		}
	}

}
